package io.github.fb513.api.queue;

import io.github.fb513.common.constant.RabbitConstants;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * @author fengbo
 * @since 2023/12/26 10:12
 */
@Component
public class MessageSender {

    @Autowired
    private RabbitTemplate rabbitTemplate;
    @Autowired
    private ThreadPoolExecutor executor;

    public void send(String brokerId, String msg) {
        rabbitTemplate.convertAndSend(RabbitConstants.web_to_im_message, brokerId, msg);
    }

    public void sendAsync(String brokerId, String msg) {
        executor.execute(() -> send(brokerId, msg));
    }
}
